package com.htandroid.reconstitute.http;

import com.htandroid.reconstitute.utils.ToastUtil;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.Map;

import okhttp3.Call;

public class OkHttpRequestUtils {

    public static OkHttpRequestUtils okHttpRequestUtils ;

    public OkHttpRequestUtils() {
    }

    public static synchronized OkHttpRequestUtils getOkHttpRequestUtils() {
        if (okHttpRequestUtils == null) {
            synchronized (OkHttpRequestUtils.class) {
                if (okHttpRequestUtils == null) {
                    okHttpRequestUtils = new OkHttpRequestUtils();
                }
            }
        }
        return okHttpRequestUtils;
    }

    /**
     * Get请求
     * @param mParams
     * @param mUrl
     */
    public void doGet(Map<String,String> mParams,String mUrl){
        OkHttpUtils.get().url(mUrl).params(mParams).build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                String message = e.getMessage();

            }

            @Override
            public void onResponse(String response, int id) {
                String s = response.toString();

            }
        });
    }

    /**
     * Post请求
     * @param mParams
     * @param mUrl
     */
    public void doPost(Map<String,String> mParams,String mUrl){
        OkHttpUtils.post().url(mUrl).params(mParams).build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                String message = e.getMessage();
                ToastUtil.showToast("服务异常-"+message);

            }

            @Override
            public void onResponse(String response, int id) {
                String string = response.toString();

            }
        });

    }

}
